import Cookies from "js-cookie";

// 设置setLocalStorage
export function setLocalStorage(key, value) {
  window.localStorage.setItem(key, window.JSON.stringify(value));
}

//获取getLocalStorage
export function getLocalStorage(key) {
  return window.JSON.parse(window.localStorage.getItem(key) || "[]");
}

// 设置setSessionStorage
export function setSessionStorage(key, value) {
  window.sessionStorage.setItem(key, window.JSON.stringify(value));
}

// 获取getSessionStorage
export function getSessionStorage(key) {
  return window.JSON.parse(window.sessionStorage.getItem(key) || "[]");
}

//  获取getCookie
export function getCookie(key) {
  return Cookies.get(key) ? JSON.parse(Cookies.get(key)) : {};
}

// 设置setCookie
export function setCookie(key, value) {
  let num = 2; // 失效时间是几小时
  let time = new Date(new Date().getTime() + num * 60 * 60 * 1000);
  return Cookies.set(key, value, {
    expires: time
  });
}

// 移除removeCookie
export function removeCookie(key) {
  return Cookies.remove(key);
}
